package com
{
	import org.jivesoftware.xiff.conference.Room;
	import org.jivesoftware.xiff.core.JID;
	import org.jivesoftware.xiff.core.XMPPSocketConnection;
	import org.jivesoftware.xiff.events.LoginEvent;
	import org.jivesoftware.xiff.events.RoomEvent;
	import org.jivesoftware.xiff.events.XIFFErrorEvent;
	
	import mx.controls.Alert;
	
	public class Chat
 	{
 		private var connection:XMPPSocketConnection;
 		
		public function Chat(_user:String, _mdp:String)
		{
			connection = new XMPPSocketConnection();
			connection.username = _user;
			connection.password = _mdp;
			connection.server = "im.apinc.org";
			connection.port = 443;

			connection.addEventListener(LoginEvent.LOGIN, onLogin);
    		connection.addEventListener(XIFFErrorEvent.XIFF_ERROR, onError);	

			connection.connect("standard");
		}
		
		private function onLogin(e:LoginEvent):void
		{
			var room:Room = new Room(connection);
			room.roomJID = new JID("test@conference.mesh.local");
			room.addEventListener(RoomEvent.ROOM_JOIN, onRoomJoin);
			room.join();
		}
		
		private function onRoomJoin(e:RoomEvent):void
		{
			Room(e.target).sendMessage("im here");
		}
		
		private function onError(e:XIFFErrorEvent):void
		{
			Alert.show(e.errorCode.toString());
		}

	}
}